package com.esyoga.yoyoga.util;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

/**
 *  用于教练时间的放入和提取
 *  存放规则
 *  Map的key分别为Monday,Tuesday,Wednesday,Thursday,Friday
 *  Map的value的List中存放3个Integer值，分别对应早中晚，其中0为有空，1为没空
 *
 */
public class TrainerTimeUtil {

    private static String[] weekString={"Monday","Tuesday","Wednesday","Thursday","Friday"};

    /**
     * 获取TimeMap集合，具体规则参考类注释
     * @param TimeString    取出的时间字符串
     * @return              TimeMap集合
     */
    public static Map<String, List<Integer>> getTimeMapByTimeString(String TimeString){
        Map<String, List<Integer>> TimeMap = new Hashtable<>();
        String[] weekTimeStrings = TimeString.split(";");
        for (int i = 0 ;i < weekTimeStrings.length;i++){
            String currentDay = weekTimeStrings[i];
            String[] currentDayStatus = currentDay.split(",");
            List<Integer> currentDayTimeList = new ArrayList<>();
            for (int j= 0;j<currentDayStatus.length;j++){
                currentDayTimeList.add(Integer.parseInt(currentDayStatus[j]));
            }
            TimeMap.put(weekString[i],currentDayTimeList);
        }
        return TimeMap;
    }

    /**
     * 获取TimeMapinfo集合
     * @param TimeString    取出的时间字符串
     * @return              TimeMapInfo集合
     */
    public static Map<String, String> getTimeMapInfoByTimeString(String TimeString){
        Map<String, String> TimeMap = new Hashtable<>();
        String[] weekTimeStrings = TimeString.split(";");
        for (int i = 0 ;i < weekTimeStrings.length;i++){
            String currentDay = weekTimeStrings[i];
            String[] currentDayStatus = currentDay.split(",");
            String currentDayInfo = "";
            if (currentDayStatus[0].equals("1")){
                currentDayInfo += "09:00-11:00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            }
            if (currentDayStatus[1].equals("1")){
                currentDayInfo += "13:00-15:00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            }
            if (currentDayStatus[2].equals("1")){
                currentDayInfo += "16:00-18:00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            }
            TimeMap.put(weekString[i],currentDayInfo);
        }
        return TimeMap;
    }

    /**
     * 获取TimeString字符串，具体规则参考类注释
     * @param TimeMap       取出的TimeMap集合
     * @return              TimeString字符串
     */
    public static String getTimeStringByTimeMap(Map<String, List<Integer>> TimeMap){
        List<Integer> Monday = TimeMap.get("Monday");
        List<Integer> Tuesday = TimeMap.get("Tuesday");
        List<Integer> Wednesday = TimeMap.get("Wednesday");
        List<Integer> Thursday = TimeMap.get("Thursday");
        List<Integer> Friday = TimeMap.get("Friday");

        String MondayTimeString = Monday.get(0)+","+Monday.get(1)+","+Monday.get(2);
        String TuesdayTimeString = Tuesday.get(0)+","+Tuesday.get(1)+","+Tuesday.get(2);
        String WednesdayTimeString = Wednesday.get(0)+","+Wednesday.get(1)+","+Wednesday.get(2);
        String ThursdayTimeString = Thursday.get(0)+","+Thursday.get(1)+","+Thursday.get(2);
        String FridayTimeString = Friday.get(0)+","+Friday.get(1)+","+Friday.get(2);

        String TimeString = MondayTimeString+";"+TuesdayTimeString+";"+WednesdayTimeString+";"+ThursdayTimeString+";"+FridayTimeString;

        return TimeString;
    }

}
